<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>我的</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" type="text/css" href="../../css/mui.picker.min.css" />
		<link rel="stylesheet" type="text/css" href="../../css/mui.poppicker.css" />
		<link rel="stylesheet" href="../../css/mui.min.css">
		<link rel="stylesheet" href="../../css/allApp.css" />
		<style>
			html,
			body {
				width: 100%;
				height: 100%;
				background: url(../login/img/login_bg.png) no-repeat bottom;
				background-size: 100%;
			}
			
			.mui-bar {
				background: transparent;
				border-bottom: 1px solid transparent;
			}
			
			.mui-bar h1 {
				color: #FFFFFF;
				line-height: 46px;
				top: 2px;
			}
			
			.mui-bar-nav {
				box-shadow: 0 1px 6px transparent;
			}
			
			.mui-content {
				margin-top: -25px;
				padding-top: 0!important;
				width: 100%;
				height: 100%;
				/*background: #FFFFFF;*/
			}
			/*.working {
				position: absolute;
				top: 50%;
				left: 50%;
				background: #FFFFFF;
				transform: translate(-50%, -50%);
				height: 30vw;
				width: 50%;
				line-height: 30vw;
				text-align: center;
			}*/
			
			.logo {
				width: 50vw;
				/*margin: 42vh 25vw;
				margin-bottom: 15vw;*/
				position: absolute;
				top: 92%;
				left: 50%;
				transform: translate(-50%, -50%);
				-ms-transform:translate(-50%, -50%); 	/* IE 9 */
				-moz-transform:translate(-50%, -50%); 	/* Firefox */
				-webkit-transform:translate(-50%, -50%); /* Safari 和 Chrome */
				-o-transform:translate(-50%, -50%); 	/* Opera */
			}
			
			.avatar {
				background-color: transparent;
				/*padding: 15px 0;*/
				border-bottom: 1px solid transparent;
				background: url(img/myBg.png) no-repeat;
				background-size: 100% 225px;
				/*margin-top: 5px;*/
				height: 225px;
			}
			
			.avatarImg {
				width: 20vw;
				border: 1px solid transparent;
				border-radius: 50%;
				height: 20vw;
				overflow: hidden;
				position: absolute;
				top: 109.5px;
				left: 40.4%;
			}
			
			.avatarImg img {
				width: 100%;
				height: 100%;
			}
			
			.userInfo {
				background: #FFFFFF;
				margin-top: 10px;
				/*padding: 15px 0;*/
			}
			
			.mui-input-row label {
				/*padding-left: 10%;*/
				height: 50px;
				line-height: 50px;
				padding: 0 0 0 10%;
			}
			
			.mui-input-row label~input {
				height: 50px;
				line-height: 50px;
				text-align: right;
				padding-right: 10%;
				color: rgba(0, 0, 0, .5);
			}
			
			.mui-input-row {
				border-bottom: 1px solid #EDEDED;
				height: 50px;
				line-height: 50px;
			}
			
			@media only screen and (min-width: 100px) and (max-width: 340px) {
				.avatar {
					background-color: transparent;
					/*padding: 15px 0;*/
					border-bottom: 1px solid transparent;
					background: url(img/myBg.png) no-repeat;
					background-size: 100% 183px;
					/*margin-top: 5px;*/
					height: 186px;
				}
				.avatarImg {
					width: 20vw;
					border: 1px solid transparent;
					border-radius: 50%;
					height: 20vw;
					overflow: hidden;
					position: absolute;
					top: 82.5px;
					left: 40.3%;
				}
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<h1 class="mui-title">我的</h1>
		</header>
		<div class="mui-content">
			<!--<img src="img/login_logo.png" alt="" class="logo" id="logo" />-->
			<div class="avatar">
				<div class="avatarImg">
					<img src="img/userHead.png" />
				</div>

			</div>
			<div class="userInfo">
				<div class="mui-input-row">
					<label for="">登录名:</label>
					<input type="text" id="loginName" readonly="readonly" />
				</div>
				<div class="mui-input-row">
					<label for="">姓名:</label>
					<input type="text" id="userName" readonly="readonly" />
				</div>
				<div class="mui-input-row">
					<label for="">所在公司:</label>
					<input type="text" id="unit" readonly="readonly" />
				</div>

			</div>
			<div class="userInfo">
				<div class="mui-input-row">
					<label for="">更换场站:</label>
					<input type="text" id="replace" readonly="readonly" value="" style="width: 55%;float: left;padding-right:5%" />
					<span id="replace_icon" style="float: left;color: rgba(0, 0, 0, .5);">
						>
					</span>
				</div>
			</div>
			<div class="userInfo">
				<div class="mui-input-row">
					<label for="">版本号:</label>
					<input type="text" id="version" readonly="readonly" />
				</div>
				<div class="mui-input-row">
					<label for="">清除缓存</label>
					<input type="text" id="clearTemp" readonly="readonly" value=">" />
				</div>
			</div>

			<div class="quit" style="margin-top: 5%;background: #FFFFFF;padding-top: 5%;">
				<button class="mui-btn" style="background: #074A83;color: #FFFFFF;width: 80%;margin-left: 10%;height:40px;line-height: 28px;font-size: 17px;">退出登录</button>
				<p style="padding-top: 5%;text-align: center;">Copyright ©2018-中广核新能源. All rights reserved.</p>
			</div>

		</div>

		<!--<div class="working">
			功能开发中...
		</div>-->
	</body>
	<script src="../../js/mui.min.js"></script>
	<script type="text/javascript" src="../../js/mkeyplus.base.js"></script>
	<script src="../../js/mui.picker.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../js/mui.poppicker.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../js/mui.dtpicker.js"></script>
	<script type="text/javascript" src="../../js/vue.js"></script>
	<script type="text/javascript" src="../../js/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="../../js/common.js"></script>
	<script>
		mui.init();
		mui.plusReady(function() {
			plus.screen.lockOrientation("portrait-primary");
			var btnArr = ['确认', '取消'];
			getUserInfo();

			$('#clearTemp').on('tap', function() {
				var btnArr = ['确定', '取消'];
				mui.confirm('确认清除缓存吗?将会清除草稿箱中的内容!', '清除缓存提示', btnArr, function(e) {
					if(e.index == "0") {
						localStorage.removeItem("fd_draft");
						localStorage.removeItem("savexcxj");
						mui.toast('缓存已经清理!');
					}
				});

			});
			$('.quit').on('tap', function() {
				mui.confirm('确认退出吗?', '提示', btnArr, function(e) {
					//					if(localStorage.getItem('uname') == "P000009") {
					//						localStorage.removeItem('uname');	
					//						localStorage.setItem('uname','P000010');
					//						plus.webview.getWebviewById('login.html').evalJS('getUsername()');
					//					}
					//					if(localStorage.getItem('uname') == "P000010") {
					//						localStorage.removeItem('uname');
					//						localStorage.setItem('uname','P000009');
					//						plus.webview.getWebviewById('login.html').evalJS('getUsername()');
					//					}
					if(e.index == "0") {
						localStorage.removeItem("pwd");
						localStorage.removeItem("username");
						mui.openWindow({
								url:"../login/login.html",
								id:"../login/login.html",
							  	waiting:{
							  		 autoShow:false,
							  	}
							});
							setTimeout(function(){
								var homeView = plus.webview.getWebviewById("../../index1.html");
			  					homeView.close("none");
							},500);
//						plus.runtime.restart(); // 重启当前应用,跳回首页
					}
				});

			});

		});
		//获取用户信息缓存
		function getUserInfo() {
			getVersion();
			$('#loginName').val(localStorage.getItem('uname')); // 登录名
			$('#userName').val(localStorage.getItem('xingming')); // 用户姓名
			var windName = JSON.parse(localStorage.getItem('windName'));
			$('#replace').val(windName); // 电场名字
			console.log(" " + localStorage.getItem('unit'));
			console.log("windNamewindNamewindName " + localStorage.getItem('windName'));
			if(localStorage.getItem('unit') != "null") {
				$('#unit').val(localStorage.getItem('unit')); // 用户所在公司	
			} else {
				$('#unit').val("");
			}

			// 版本号
		}

		function getVersion() {
			plus.runtime.getProperty(plus.runtime.appid, function(inf) {
				//判断是否有忽略的版本
				var temp = inf.version;
				//		 	localStorage.setItem("currVersion",temp);
				$('#version').val(temp);
			});
		}
		var replacedata = "";
		var Id = "";
		var Text = "";

		//更换电站
		document.getElementById('replace').addEventListener('tap', function() {
			pickdata();
		});
		//更换电站
		document.getElementById('replace_icon').addEventListener('tap', function() {
			pickdata();
		});

		function pickdata() {
			plus.nativeUI.showWaiting();
			mui.baseApp.httpRequst('/api/v2/users/windList', {
					userid: localStorage.getItem('userid')
				},
				function(res) {
					plus.nativeUI.closeWaiting();
					var data = res.data;
					if(res.status == 200) {
						console.log("电场" + JSON.stringify(data))
						replacedata = data;
						pick(replacedata);
					} else if(res.status == 500) {
						mui.toast(data.message)
					}
				}
			);
		}

		function pick(replacedata) {
			var gzzjArr1 = [];
			var picker = new mui.PopPicker();
			$.each(replacedata, function(i, v) {
				gzzjObj1 = {
					value: v.id,
					text: v.name,
					org_code: v.org_code
				}
				gzzjArr1.push(gzzjObj1);
			});
			console.log("+++++"+JSON.stringify(gzzjArr1))
			picker.setData(gzzjArr1);

			$.each(gzzjArr1, function(i, v) {			
				if(JSON.parse(localStorage.getItem('windName')) == v.text) {
					picker.pickers[0].setSelectedIndex(i);					
				} 
			});
			picker.show(function(selectItems) {
				console.log('selectItems===' + JSON.stringify(picker.getSelectedItems(selectItems)))
				//localStorage.setItem("org_code",picker.getSelectedItems(selectItems)[0].org_code);
				Text=picker.getSelectedItems(selectItems)[0].text;
				Id = picker.getSelectedItems(selectItems)[0].value;
				console.log("Id" + Id);
				getSucess(Id);
			});
		}

		function getSucess(Id) {
			
			mui.baseApp.httpRequst('/api/v2/users/updateUserWind', {
					username: localStorage.getItem('uname'),
					orgid: Id
				},
				function(data) {
					if(data.status == 200) {
						/*var page = plus.webview.getWebviewById("pages/index1/shouye1.html");
						page.evalJS('getorg()');*/
//						xunjian(Id);
						$('#replace').val(Text);
						var page = plus.webview.getWebviewById("pages/index1/shouye1.html");
						page.evalJS('getorg()');
						page.evalJS('home()');
						mui.toast(data.message);
					} else if(data.status == 400) {

						mui.toast(data.message);
					} else if(data.status == 500) {
						mui.toast(data.message);
					}
				}
			);
						
		}
		var AppId = mui.baseApp.AppId; //APPid
		var AppKey = mui.baseApp.AppKey; // AppKey
		var AppSecret = mui.baseApp.AppSecret; // AppSecret
		var version; // 版本
		var timestamp = Date.parse(new Date()); // 时间戳
		var token = '1';
		var OSType; // 系统
		var DGUID;
		version = localStorage.getItem('version'); // 版本
		OSType = (mui.os.ios) ? "ios" : "android"; // 系统
		if(localStorage.getItem("uuid") == null || localStorage.getItem("uuid") == "") {
			DGUID = plus.device.uuid;
			localStorage.setItem("uuid", param.DGUID);
		} else {
			DGUID = localStorage.getItem("uuid");
		}
		//巡检服务器接口
		function xunjian(Id){
			console.log(Config.xjurl+'/api/v2/users/updateUserWind');
			mui.ajax(Config.xjurl+'/api/v2/users/updateUserWind', {
				data: {
					username: localStorage.getItem('uname'),
					orgid: Id,
					AppId: AppId,
					AppKey: AppKey,
					AppSecret: AppSecret,
					version: version,
					timestamp: timestamp,
					OSType: OSType,
					DGUID: DGUID
				},
				dataType: 'json',
				type: 'POST',
				timeout: 10000,
				success: function(data) {
					if(data.status == 200) {
						$('#replace').val(Text);
						var page = plus.webview.getWebviewById("pages/index1/shouye1.html");
						page.evalJS('getorg()');
						page.evalJS('home()');
						mui.toast(data.message);
					} else if(data.status == 400) {

						mui.toast(data.message);
					} else if(data.status == 500) {
						mui.toast(data.message);
					}
				},
				error: function() {}
			})
		}
	</script>

</html>